classdef cModel
    %UNTITLED2 Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
        % Model parameters, varying with different machines
        pAlpha = 0.95;
        pLambda = 0.9; % ml.g(-1)
        pTI2 = 0;    % Should be set manually according the sampling time
        pT1b = 1.5;
        pTau = 0.7; % in seconds
        
        pM0 = [];
        pSlice = 1;
    end
    
    methods
        function [dictionary,t] = curvefitting_asl_model(obj,x,t)
            f = x(1); deltat = x(2);
            
            tau = obj.pTau;
            if isempty(obj.pM0)
                M0 = 1;
            else
                M0 = obj.pM0;
            end
            
            lambda = obj.pLambda;
            T1b = obj.pT1b;
            alpha = obj.pAlpha;
            s = obj.pSlice;
            
            N = length(t);
            dictionary = zeros(N,1);
            for i=1:N
                if t(i) < deltat
                    dictionary(i) = 0;
                elseif t(i)< tau+deltat
                    dictionary(i) = 2*alpha*M0*f*exp(-(t(i))/T1b).*(t(i)-deltat)/6000;
                else
                    dictionary(i) = 2*alpha*M0*f*exp(-(t(i))/T1b)*tau/6000;
                end
            end
            
        end
        
        
        % This function is to build an dictionary with normalized columns
        function [dictionary,AmplitudeD] = cmf_asl_model(obj,f,deltat,t)
            
            dictionary = zeros(length(t),length(deltat));
            for i = 1:length(deltat)
                x(1) = f;x(2) = deltat(i);
                [ dictionary(:,i),t ] = obj.curvefitting_asl_model(x,t);
            end
            
            
            [d,k] = size(dictionary);
            % Normalize the dictionary
            AmplitudeD = zeros(k,1);
            for i=1:k
                AmplitudeD(i) = norm(dictionary(:,i));
%                 dictionary(:,i) = dictionary(:,i)/norm(dictionary(:,i));
            end
        end
        
    end
end
    
